const utils = require("../../../utils/utils");
//获取应用实例
const app = getApp()
Page({
    data: {
        oldSrc: '',
        src: '',
        width: 300, //宽度
        height: 300, //高度
        disable_width: true,
        disable_height: true,
        disable_rotate: true, //是否禁用旋转
        disable_ratio: true, //锁定比例
        limit_move: false, //是否限制移动
        addList: 0,
        isShow: false,
        mengHeight: 0,
        export_scale: 4,
        pdbper: 0,
        temps: [],
        imgUrl: '',
        imgId: 0,
        chooseTempIndex: 0,
        filters: [],
        requestUrl: '',
        appkey: '',
        intoView: 'viewshi',
        pid: ''
    },
    //旋转
    rotate() {
        //在用户旋转的基础上旋转90°
        this.cropper.setAngle(this.cropper.data.angle += 90);
    },
    //重置
    reset() {
        var that = this;
        that.cropper.imgReset();
    },
    //确定
    submitBtn() {
        var that = this;
        if (!utils.is_define(that.cropper.data.imgSrc)) {
            utils.toast('请先点击页面中央部位上传图片')
            return false;
        }
        wx.showLoading({
            title: '美好值得等待'
        })
        that.cropper.getImg((obj) => {
            if (that.data.code == '12653870') {
                that.repair(obj.url)
            } else if (that.data.code == '11543462') {
                that.cartoon(obj.url)
            } else {
                that.uploadFile(obj.url, '', that.data.code);
            }
        });
    },
    //卡通形象
    cartoon(img) {
        var that = this;
        utils.request('Index/photoCartoonFace', {}, function (res) {
            if (res.data.code == 1) {
                that.setData({
                    requestUrl: res.data.data.requestUrl
                })
                utils.mtuploadfile(img, function (res) {
                    var result = JSON.parse(res.data)
                    that.setData({
                        appkey: result.key
                    })
                    // 拼接卡通形象参数
                    var obj = {
                        "media_info_list": [{
                            "media_data": result.key,
                            "media_extra": {},
                            "media_profiles": {
                                "media_data_type": "key"
                            }
                        }],
                        "parameter": {
                            "rsp_media_type": "url",
                            "taskType": 3
                        },
                        "client_id": "1189857369",
                        "version": 8610
                    }
                    utils.requestMT(that.data.requestUrl, JSON.stringify(obj), function (res) {
                        wx.hideLoading()
                        if (res.data.ErrorCode == 20003) {
                            wx.showModal({
                                title: '提示',
                                content: '未检测到人脸，请返回重新上传',
                                showCancel: false,
                                success(res) {
                                    if (res.confirm) {
                                        wx.navigateBack()
                                    }
                                }
                            })
                        } else if (res.data.ErrorCode == 20004) {
                            wx.showModal({
                                title: '提示',
                                content: '只支持单人照，请返回重新上传',
                                showCancel: false,
                                success(res) {
                                    if (res.confirm) {
                                        wx.navigateBack()
                                    }
                                }
                            })
                        } else {
                            if (utils.is_define(res.data.media_info_list)) {
                                res.data.oimg = img
                                var nimg = escape(res.data.media_info_list[0].media_data)
                                wx.redirectTo({
                                    url: '../../Allphoto/cartoon/cartoon?img=' + nimg + '&oimg=' + img
                                })
                            } else {
                                utils.toast('修复失败，清重试')
                            }
                        }
                    })
                })
            }
        })
    },
    //修复照片
    repair(img) {
        var that = this;
        utils.request('Index/photoAiquality', {}, function (res) {
            if (res.data.code == 1) {
                that.setData({
                    requestUrl: res.data.data.requestUrl
                })
                utils.mtuploadfile(img, function (res) {
                    var result = JSON.parse(res.data)
                    that.setData({
                        appkey: result.key
                    })
                    // 拼接老照片修复参数
                    var obj = {
                        "media_info_list": [{
                            "media_data": result.key,
                            "media_extra": {},
                            "media_profiles": {
                                "media_data_type": "key"
                            }
                        }],
                        "parameter": {
                            "rsp_media_type": "url"
                        },
                        "client_id": "1189857369",
                        "version": 8610
                    }
                    utils.requestMT(that.data.requestUrl, JSON.stringify(obj), function (res) {
                        wx.hideLoading()
                        if (utils.is_define(res.data.media_info_list[0].media_data)) {
                            res.data.oimg = img
                            var nimg = escape(res.data.media_info_list[0].media_data)
                            wx.redirectTo({
                                url: '../../Allphoto/repair/repair?img=' + nimg + '&oimg=' + img
                            })
                        } else {
                            utils.toast('修复失败，清重试')
                        }
                    })
                })
            }
        })
    },
    //上传图片
    uploadFile(path, name, code) {
        var that = this;
        utils.uploadfile(path, path, '', '', '', function (res) {
            var data = JSON.parse(res.data).data
            wx.hideLoading()
            //如果是证件照，要先处理
            if (code == '31179418' || code == '23002888' || code == '29733714' || code == '92673031' || code == '27007881' || code == '43969370' || code == '17094958' || code == '32663242' || code == '85577502' || code == '32372752' || code == '52895860' || code == '33024820' || code == '49321510' || code == '10765365' || code == '12871293') {
                var w = that.data.width;
                var h = that.data.height;
                wx.redirectTo({
                    url: '../papersEdit/papersEdit?&code=' + code + '&icon=' + data.fileIcon + '&w=' + w + '&h=' + h + '&url=' + data.url + '&picType=' + that.data.picType + '&pid=' + that.data.pid,
                })
                // that.makingCard(code,data.fileIcon,data.url)
            }
            if (code == 'idCard') {
                //身份证
                let pages = getCurrentPages();
                let prevPage = pages[pages.length - 2];
                if (that.data.type == 'zm') {
                    prevPage.setData({
                        zmimg: data.printUrl,
                        zmOss: data.printUrl,
                        robotzm: 1
                    })
                }
                if (that.data.type == 'fm') {
                    prevPage.setData({
                        fmimg: data.printUrl,
                        fmOss: data.printUrl,
                        robotfm: 1
                    })
                }
                wx.navigateBack();
            }
            // 原片或画中画
            if (code == '31414754' || code == '30177105') {
                if (utils.is_define(that.data.imgId) && that.data.imgId != 0) {
                    that.tempToimg(data.url, data.name, code, data.fileIcon, data.pageNum);
                } else {
                    if (that.data.addList == 1) {
                        let pages = getCurrentPages();
                        let prevPage = pages[pages.length - 2];
                        var obj = {};
                        obj.currentNum = 1;
                        obj.pageNum = data.pageNum;
                        obj.fileUrl = data.url;
                        obj.name = data.name;
                        obj.code = code;
                        obj.currentFull = 1;
                        obj.currentColor = 2;
                        obj.currentFace = 1;
                        obj.currentPaper = 1;
                        prevPage.setData({
                            currentObj: obj,
                            type: 2,
                            without: true
                        })
                        wx.navigateBack();
                    } else {
                        wx.redirectTo({
                            url: '../list/list?code=' + code + '&name=' + data.name + '&icon=' + data.fileIcon + '&path=' + data.url + '&pageNum=' + data.pageNum,
                        })
                    }
                }
            }
            // 滤镜 胡子 童年穿越  毕业照  跨次元 人物绘画
            if (code == '32218178' || code == '38668456' || code == '26850318' || code == '29756116' || code == '23844984' || code == '27814624') {
                wx.redirectTo({
                    url: '../list/list?code=' + code + '&name=' + data.name + '&icon=' + data.fileIcon + '&path=' + data.url + '&pageNum=' + data.pageNum,
                })
            }

        })
    },
    //mu模板合成
    tempToimg(url, name, code, icon, pageNum) {
        wx.showLoading({
            title: '合成中',
        })
        var that = this;
        var data = {
            'remoteUrl': url,
            'catCode': that.data.imgId
        }
        utils.request('photo/picture', data, function (res) {
            wx.hideLoading()
            if (res.data.code == 1) {
                if (that.data.addList == 1) {
                    let pages = getCurrentPages();
                    let prevPage = pages[pages.length - 2];
                    var obj = {};
                    obj.currentNum = 1;
                    obj.pageNum = res.data.data.pageNum;
                    obj.fileUrl = res.data.data.fileUrl;
                    obj.name = name;
                    obj.currentFull = 1;
                    obj.code = code;
                    obj.currentColor = 2;
                    obj.currentFace = 1;
                    obj.currentPaper = 1;
                    prevPage.setData({
                        currentObj: obj,
                        type: 2,
                        without: true
                    })
                    wx.navigateBack();
                } else {
                    wx.redirectTo({
                        url: '../list/list?code=' + code + '&name=' + name + '&icon=' + icon + '&path=' + res.data.data.fileUrl + '&pageNum=' + res.data.data.pageNum,
                    })
                }
            } else {
                utils.toast(res.data.msg)
            }
        })
    },
    //获取胡子特效素材
    getbeardS() {
        var that = this;
        utils.request('Index/photoBeard', {}, function (res) {
            if (res.data.code == 1) {
                var query = wx.createSelectorQuery();
                query.select('#editBottom').boundingClientRect()
                // + (wx.getSystemInfoSync().screenHeight - wx.getSystemInfoSync().safeArea.bottom) + 40
                query.exec(function (ret) {
                    //res就是 所有标签为mjltest的元素的信息 的数组
                    //取高度
                    that.setData({
                        pdbper: ret[0].height,
                        temps: res.data.data.cat,
                        requestUrl: res.data.data.requestUrl
                    })
                })
            } else {
                utils.toast(res.data.msg)
            }
        })
    },
    //获取毕业照特效素材
    getgraduationS() {
        var that = this;
        utils.request('Index/photoGraduation', {}, function (res) {
            if (res.data.code == 1) {
                var query = wx.createSelectorQuery();
                query.select('#editBottom').boundingClientRect()
                // + (wx.getSystemInfoSync().screenHeight - wx.getSystemInfoSync().safeArea.bottom) + 40
                query.exec(function (ret) {
                    //res就是 所有标签为mjltest的元素的信息 的数组
                    //取高度
                    that.setData({
                        pdbper: ret[0].height,
                        temps: res.data.data.style,
                        requestUrl: res.data.data.requestUrl
                    })
                })
            } else {
                utils.toast(res.data.msg)
            }
        })
    },
    //获取跨次元特效素材
    getdimensional() {
        var that = this;
        utils.request('Index/photoAcross', {}, function (res) {
            if (res.data.code == 1) {
                var query = wx.createSelectorQuery();
                query.select('#editBottom').boundingClientRect()
                // + (wx.getSystemInfoSync().screenHeight - wx.getSystemInfoSync().safeArea.bottom) + 40
                query.exec(function (ret) {
                    //res就是 所有标签为mjltest的元素的信息 的数组
                    //取高度
                    that.setData({
                        pdbper: ret[0].height,
                        temps: res.data.data.cat,
                        requestUrl: res.data.data.requestUrl
                    })
                })
            } else {
                utils.toast(res.data.msg)
            }
        })
    },
    // */
    //获取模板
    gettmp() {
        var that = this;
        utils.request('Index/photoPicture', {}, function (res) {
            if (res.data.code == 1) {
                var query = wx.createSelectorQuery();
                query.select('#editBottom').boundingClientRect()
                // + (wx.getSystemInfoSync().screenHeight - wx.getSystemInfoSync().safeArea.bottom) + 40
                query.exec(function (ret) {
                    //res就是 所有标签为mjltest的元素的信息 的数组
                    //取高度
                    that.setData({
                        pdbper: ret[0].height,
                        temps: res.data.data.cat
                    })
                })
            }
        })
    },
    //获取滤镜参数
    getSpeFilter() {
        var that = this;
        utils.request('Index/photoFilter', {}, function (res) {
            if (res.data.code == 1) {
                var query = wx.createSelectorQuery();
                query.select('#editBottom').boundingClientRect()
                // + (wx.getSystemInfoSync().screenHeight - wx.getSystemInfoSync().safeArea.bottom) + 40
                query.exec(function (ret) {
                    //res就是 所有标签为mjltest的元素的信息 的数组
                    //取高度
                    that.setData({
                        pdbper: ret[0].height,
                        filters: res.data.data.cat,
                        requestUrl: res.data.data.requestUrl
                    })
                })
            }
        })
    },
    //童年穿越素材
    getchildhood() {
        var that = this;
        utils.request('Index/photoChild', {}, function (res) {
            if (res.data.code == 1) {
                var query = wx.createSelectorQuery();
                query.select('#editBottom').boundingClientRect()
                // + (wx.getSystemInfoSync().screenHeight - wx.getSystemInfoSync().safeArea.bottom) + 40
                query.exec(function (ret) {
                    //res就是 所有标签为mjltest的元素的信息 的数组
                    //取高度
                    that.setData({
                        pdbper: ret[0].height,
                        temps: res.data.data.cat,
                        requestUrl: res.data.data.requestUrl
                    })
                })
            } else {
                utils.toast(res.data.msg)
            }
        })
    },
    //人物绘画素材
    getdisney() {
        var that = this;
        utils.request('Index/photoDisney', {}, function (res) {
            if (res.data.code == 1) {
                var query = wx.createSelectorQuery();
                query.select('#editBottom').boundingClientRect()
                // + (wx.getSystemInfoSync().screenHeight - wx.getSystemInfoSync().safeArea.bottom) + 40
                query.exec(function (ret) {
                    //res就是 所有标签为mjltest的元素的信息 的数组
                    //取高度
                    that.setData({
                        pdbper: ret[0].height,
                        temps: res.data.data.cat,
                        requestUrl: res.data.data.requestUrl
                    })
                })
            } else {
                utils.toast(res.data.msg)
            }
        })
    },
    choosetempIndex(e) {
        var index = e.currentTarget.dataset.index;
        this.setData({
            chooseTempIndex: index,
            intoView: 'viewshi'
        })
    },
    choosemb(e) {
        var that = this;
        var imgUrl = e.currentTarget.dataset.imgurl;
        var imgId = e.currentTarget.dataset.imgid;
        var index = e.currentTarget.dataset.index;
        //画中画选择模板
        if (that.data.code == '30177105') {
            if (imgId == that.data.imgId) {
                return false;
            }
            that.setData({
                imgUrl: imgUrl,
                imgId: imgId,
                intoView: 'view' + index
            })
            if (imgId != 0) {
                wx.showLoading()
            }
        }
        //人物绘画选择模板
        if (that.data.code == '27814624') {
            wx.showLoading({
                title: '美好值得等待'
            })
            if (imgId == 0) {
                that.setData({
                    src: imgUrl,
                    imgId: 0,
                    intoView: "viewshi"
                })
                wx.hideLoading()
                return false;
            }
            // 这块要先上传获取一下key值
            if (utils.is_define(that.data.appkey)) {
                // 拼接人物绘画模板参数
                var obj = {
                    "media_info_list": [{
                        "media_data": that.data.appkey,
                        "media_profiles": {
                            "media_data_type": "key"
                        }
                    }],
                    "parameter": {
                        "type": "0",
                        "cartoonType": that.data.temps[that.data.chooseTempIndex].next[index].config.cartoonType,
                        "filterType": that.data.temps[that.data.chooseTempIndex].next[index].config.filterType,
                        "backgroundType": that.data.temps[that.data.chooseTempIndex].next[index].config.backgroundType,
                        "makeupType": that.data.temps[that.data.chooseTempIndex].next[index].config.makeupType,
                        "use3X": that.data.temps[that.data.chooseTempIndex].next[index].config.use3X,
                        "rsp_media_type": "url"
                    }
                }
                utils.requestMT(that.data.requestUrl, JSON.stringify(obj), function (res) {
                    wx.hideLoading()
                    if (res.data.ErrorCode == 20003) {
                        wx.showModal({
                            title: '提示',
                            content: '未检测到人脸，请返回重新上传',
                            showCancel: false,
                            success(res) {
                                if (res.confirm) {
                                    wx.navigateBack()
                                }
                            }
                        })
                    } else if (res.data.ErrorCode == 20004) {
                        wx.showModal({
                            title: '提示',
                            content: '只支持单人照，请返回重新上传',
                            showCancel: false,
                            success(res) {
                                if (res.confirm) {
                                    wx.navigateBack()
                                }
                            }
                        })
                    } else {
                        that.setData({
                            src: res.data.media_info_list[0].media_data,
                            imgId: imgId,
                            intoView: 'view' + index
                        })
                    }
                })
            } else {
                utils.mtuploadfile(imgUrl, function (res) {
                    var result = JSON.parse(res.data)
                    that.setData({
                        appkey: result.key
                    })
                    // 拼接人物绘画参数
                    var obj = {
                        "media_info_list": [{
                            "media_data": result.key,
                            "media_profiles": {
                                "media_data_type": "key"
                            }
                        }],
                        "parameter": {
                            "type": "0",
                            "cartoonType": that.data.temps[that.data.chooseTempIndex].next[index].config.cartoonType,
                            "filterType": that.data.temps[that.data.chooseTempIndex].next[index].config.filterType,
                            "backgroundType": that.data.temps[that.data.chooseTempIndex].next[index].config.backgroundType,
                            "makeupType": that.data.temps[that.data.chooseTempIndex].next[index].config.makeupType,
                            "use3X": that.data.temps[that.data.chooseTempIndex].next[index].config.use3X,
                            "rsp_media_type": "url"
                        }
                    }
                    utils.requestMT(that.data.requestUrl, JSON.stringify(obj), function (res) {
                        wx.hideLoading()
                        if (res.data.ErrorCode == 20003) {
                            wx.showModal({
                                title: '提示',
                                content: '未检测到人脸，请返回重新上传',
                                showCancel: false,
                                success(res) {
                                    if (res.confirm) {
                                        wx.navigateBack()
                                    }
                                }
                            })
                        } else if (res.data.ErrorCode == 20004) {
                            wx.showModal({
                                title: '提示',
                                content: '只支持单人照，请返回重新上传',
                                showCancel: false,
                                success(res) {
                                    if (res.confirm) {
                                        wx.navigateBack()
                                    }
                                }
                            })
                        } else {
                            that.setData({
                                src: res.data.media_info_list[0].media_data,
                                imgId: imgId,
                                intoView: 'view' + index
                            })
                        }
                    })
                })
            }
        }
        //跨次元选择模板
        if (that.data.code == '23844984') {
            wx.showLoading({
                title: '美好值得等待'
            })
            if (imgId == 0) {
                that.setData({
                    src: imgUrl,
                    imgId: 0,
                    intoView: "viewshi"
                })
                wx.hideLoading()
                return false;
            }
            // 这块要先上传获取一下key值
            if (utils.is_define(that.data.appkey)) {
                // 拼接跨次元参数
                var obj = {
                    "parameter": that.data.temps[index].parameter,
                    "media_info_list": [{
                        "media_data": that.data.appkey,
                        "media_profiles": {
                            "media_data_type": "key"
                        },
                        "media_extra": {}
                    }],
                    "extra": {}
                }
                utils.requestMT(that.data.requestUrl, JSON.stringify(obj), function (res) {
                    wx.hideLoading()
                    if (res.data.ErrorCode == 20003) {
                        wx.showModal({
                            title: '提示',
                            content: '未检测到人脸，请返回重新上传',
                            showCancel: false,
                            success(res) {
                                if (res.confirm) {
                                    wx.navigateBack()
                                }
                            }
                        })
                    } else if (res.data.ErrorCode == 20004) {
                        wx.showModal({
                            title: '提示',
                            content: '只支持单人照，请返回重新上传',
                            showCancel: false,
                            success(res) {
                                if (res.confirm) {
                                    wx.navigateBack()
                                }
                            }
                        })
                    } else {
                        that.setData({
                            src: res.data.media_info_list[0].media_data,
                            imgId: imgId,
                            intoView: 'view' + index
                        })
                    }
                })
            } else {
                utils.mtuploadfile(imgUrl, function (res) {
                    var result = JSON.parse(res.data)
                    that.setData({
                        appkey: result.key
                    })
                    // 拼接跨次元参数
                    var obj = {
                        "parameter": that.data.temps[index].parameter,
                        "media_info_list": [{
                            "media_data": result.key,
                            "media_profiles": {
                                "media_data_type": "key"
                            },
                            "media_extra": {}
                        }],
                        "extra": {}
                    }
                    utils.requestMT(that.data.requestUrl, JSON.stringify(obj), function (res) {
                        wx.hideLoading()
                        if (res.data.ErrorCode == 20003) {
                            wx.showModal({
                                title: '提示',
                                content: '未检测到人脸，请返回重新上传',
                                showCancel: false,
                                success(res) {
                                    if (res.confirm) {
                                        wx.navigateBack()
                                    }
                                }
                            })
                        } else if (res.data.ErrorCode == 20004) {
                            wx.showModal({
                                title: '提示',
                                content: '只支持单人照，请返回重新上传',
                                showCancel: false,
                                success(res) {
                                    if (res.confirm) {
                                        wx.navigateBack()
                                    }
                                }
                            })
                        } else {
                            that.setData({
                                src: res.data.media_info_list[0].media_data,
                                imgId: imgId,
                                intoView: 'view' + index
                            })
                        }
                    })
                })
            }
        }
        //选择童年穿越模板
        if (that.data.code == '26850318') {
            wx.showLoading({
                title: '美好值得等待'
            })
            if (imgId == 0) {
                that.setData({
                    src: imgUrl,
                    imgId: 0,
                    intoView: "viewshi"
                })
                wx.hideLoading()
                return false;
            }
            // 这块要先上传获取一下key值
            if (utils.is_define(that.data.appkey)) {
                // 拼接童年穿越参数
                var obj = {
                    "parameter": {
                        "makeupAlpha": 70,
                        "beautyAlpha": 70,
                        "rsp_media_type": "url",
                        "id": imgId,
                        "makeup_id": imgId,
                        "makeup_alpha": 70,
                        "beauty_alpha": 70,
                        "type": 0,
                        "scaleType": 2,
                        "scaleRatio": 0.85,
                        "makeupId": imgId
                    },
                    "media_info_list": [{
                        "media_data": that.data.appkey,
                        "media_profiles": {
                            "media_data_type": "key"
                        },
                        "media_extra": {}
                    }],
                    "extra": {}
                }
                utils.requestMT(that.data.requestUrl, JSON.stringify(obj), function (res) {
                    wx.hideLoading()
                    if (res.data.ErrorCode == 20003) {
                        wx.showModal({
                            title: '提示',
                            content: '未检测到人脸，请返回重新上传',
                            showCancel: false,
                            success(res) {
                                if (res.confirm) {
                                    wx.navigateBack()
                                }
                            }
                        })
                    } else if (res.data.ErrorCode == 21003) {
                        wx.showModal({
                            title: '提示',
                            content: '只支持单人照，请返回重新上传',
                            showCancel: false,
                            success(res) {
                                if (res.confirm) {
                                    wx.navigateBack()
                                }
                            }
                        })
                    } else {
                        that.setData({
                            src: res.data.media_info_list[0].media_data,
                            imgId: imgId,
                            intoView: 'view' + index
                        })
                    }
                })
            } else {
                utils.mtuploadfile(imgUrl, function (res) {
                    var result = JSON.parse(res.data)
                    that.setData({
                        appkey: result.key
                    })
                    // 拼接童年穿越参数
                    var obj = {
                        "parameter": {
                            "makeupAlpha": 70,
                            "beautyAlpha": 70,
                            "rsp_media_type": "url",
                            "id": imgId,
                            "makeup_id": imgId,
                            "makeup_alpha": 70,
                            "beauty_alpha": 70,
                            "type": 0,
                            "scaleType": 2,
                            "scaleRatio": 0.85,
                            "makeupId": imgId
                        },
                        "media_info_list": [{
                            "media_data": result.key,
                            "media_profiles": {
                                "media_data_type": "key"
                            },
                            "media_extra": {}
                        }],
                        "extra": {}
                    }
                    utils.requestMT(that.data.requestUrl, JSON.stringify(obj), function (res) {
                        wx.hideLoading()
                        if (res.data.ErrorCode == 20003) {
                            wx.showModal({
                                title: '提示',
                                content: '未检测到人脸，请返回重新上传',
                                showCancel: false,
                                success(res) {
                                    if (res.confirm) {
                                        wx.navigateBack()
                                    }
                                }
                            })
                        } else if (res.data.ErrorCode == 21003) {
                            wx.showModal({
                                title: '提示',
                                content: '只支持单人照，请返回重新上传',
                                showCancel: false,
                                success(res) {
                                    if (res.confirm) {
                                        wx.navigateBack()
                                    }
                                }
                            })
                        } else {
                            that.setData({
                                src: res.data.media_info_list[0].media_data,
                                imgId: imgId,
                                intoView: 'view' + index
                            })
                        }
                    })
                })
            }
        }
        //选择毕业照
        if (that.data.code == '29756116') {
            wx.showLoading()
            if (imgId == 0) {
                that.setData({
                    src: imgUrl,
                    imgId: 0,
                    intoView: "viewshi"
                })
                wx.hideLoading()
                return false;
            }
            // 这块要先上传获取一下key值
            if (utils.is_define(that.data.appkey)) {
                // 拼接毕业照参数
                var obj = {
                    "media_info_list": [{
                        "media_data": that.data.appkey,
                        "media_extra": {},
                        "media_profiles": {
                            "media_data_type": "key"
                        }
                    }],
                    "parameter": {
                        "rsp_media_type": "url",
                        "facefuse_id": imgId,
                        "makeup_alpha": 1,
                        "hair_mask": 0
                    }
                }
                utils.requestMT(that.data.requestUrl, JSON.stringify(obj), function (res) {
                    wx.hideLoading()
                    if (res.data.ErrorCode == 20003) {
                        wx.showModal({
                            title: '提示',
                            content: '未检测到人脸，请返回重新上传',
                            showCancel: false,
                            success(res) {
                                if (res.confirm) {
                                    wx.navigateBack()
                                }
                            }
                        })
                    } else {
                        that.setData({
                            src: res.data.media_info_list[0].media_data,
                            imgId: imgId,
                            intoView: 'view' + index
                        })
                    }
                })
            } else {
                utils.mtuploadfile(imgUrl, function (res) {
                    var result = JSON.parse(res.data)
                    that.setData({
                        appkey: result.key
                    })
                    // 拼接毕业照参数
                    var obj = {
                        "media_info_list": [{
                            "media_data": result.key,
                            "media_extra": {},
                            "media_profiles": {
                                "media_data_type": "key"
                            }
                        }],
                        "parameter": {
                            "rsp_media_type": "url",
                            "facefuse_id": imgId,
                            "makeup_alpha": 1,
                            "hair_mask": 0
                        }
                    }

                    utils.requestMT(that.data.requestUrl, JSON.stringify(obj), function (res) {
                        wx.hideLoading()
                        if (res.data.ErrorCode == 20003) {
                            wx.showModal({
                                title: '提示',
                                content: '未检测到人脸，请返回重新上传',
                                showCancel: false,
                                success(res) {
                                    if (res.confirm) {
                                        wx.navigateBack()
                                    }
                                }
                            })
                        } else {
                            that.setData({
                                src: res.data.media_info_list[0].media_data,
                                imgId: imgId,
                                intoView: 'view' + index
                            })
                        }
                    })
                })
            }
        }
        //选择胡子
        if (that.data.code == '38668456') {
            wx.showLoading()
            if (imgId == 0) {
                that.setData({
                    src: imgUrl,
                    imgId: 0,
                    intoView: "viewshi"
                })
                wx.hideLoading()
                return false;
            }
            // 这块要先上传获取一下key值
            if (utils.is_define(that.data.appkey)) {
                // 拼接滤镜参数
                var obj = {
                    "parameter": {
                        "outputType": imgId,
                        "rsp_media_type": "url"
                    },
                    "media_info_list": [{
                        "media_data": that.data.appkey,
                        "media_profiles": {
                            "media_data_type": "key"
                        }
                    }]
                }
                utils.requestMT(that.data.requestUrl, JSON.stringify(obj), function (res) {
                    wx.hideLoading()
                    if (res.data.ErrorCode == 20003) {
                        wx.showModal({
                            title: '提示',
                            content: '未检测到人脸，请返回重新上传',
                            showCancel: false,
                            success(res) {
                                if (res.confirm) {
                                    wx.navigateBack()
                                }
                            }
                        })
                    } else {
                        that.setData({
                            src: res.data.media_info_list[0].media_data,
                            imgId: imgId,
                            intoView: 'view' + index
                        })
                    }
                })
            } else {
                utils.mtuploadfile(imgUrl, function (res) {
                    var result = JSON.parse(res.data)
                    that.setData({
                        appkey: result.key
                    })
                    // 拼接胡子参数
                    var obj = {
                        "parameter": {
                            "outputType": imgId,
                            "rsp_media_type": "url"
                        },
                        "media_info_list": [{
                            "media_data": result.key,
                            "media_profiles": {
                                "media_data_type": "key"
                            }
                        }]
                    }

                    utils.requestMT(that.data.requestUrl, JSON.stringify(obj), function (res) {
                        wx.hideLoading()
                        if (res.data.ErrorCode == 20003) {
                            wx.showModal({
                                title: '提示',
                                content: '未检测到人脸，请返回重新上传',
                                showCancel: false,
                                success(res) {
                                    if (res.confirm) {
                                        wx.navigateBack()
                                    }
                                }
                            })
                        } else {
                            that.setData({
                                src: res.data.media_info_list[0].media_data,
                                imgId: imgId,
                                intoView: 'view' + index
                            })
                        }
                    })
                })
            }
        }
        //选择滤镜
        if (that.data.code == '32218178') {
            wx.showLoading()
            if (imgId == 0) {
                that.setData({
                    src: imgUrl,
                    imgId: 0,
                    intoView: "viewshi"
                })
                wx.hideLoading()
                return false;
            }
            // 这块要先上传获取一下key值
            if (utils.is_define(that.data.appkey)) {
                // 拼接滤镜参数
                var obj = {
                    "media_info_list": [{
                        "media_data": that.data.appkey,
                        "media_profiles": {
                            "media_data_type": "key"
                        }
                    }],
                    "parameter": {
                        "filterAlpha": 75,
                        "filterType": imgId,
                        "rsp_media_type": "url",
                        "virtualType": 0
                    }
                }
                utils.requestMT(that.data.requestUrl, JSON.stringify(obj), function (res) {
                    wx.hideLoading()
                    that.setData({
                        src: res.data.media_info_list[0].media_data,
                        imgId: imgId,
                        intoView: 'view' + index
                    })
                })
            } else {
                utils.mtuploadfile(imgUrl, function (res) {
                    var result = JSON.parse(res.data)
                    that.setData({
                        appkey: result.key
                    })
                    // 拼接滤镜参数
                    var obj = {
                        "media_info_list": [{
                            "media_data": result.key,
                            "media_profiles": {
                                "media_data_type": "key"
                            }
                        }],
                        "parameter": {
                            "filterAlpha": 75,
                            "filterType": imgId,
                            "rsp_media_type": "url",
                            "virtualType": 0
                        }
                    }
                    utils.requestMT(that.data.requestUrl, JSON.stringify(obj), function (res) {
                        wx.hideLoading()
                        that.setData({
                            src: res.data.media_info_list[0].media_data,
                            imgId: imgId,
                            intoView: 'view' + index
                        })
                    })
                })
            }
        }

    },
    onLoad: function (options) {
        var export_scale = 3;
        var query = wx.createSelectorQuery();
        var that = this;
        that.setData({
            export_scale: export_scale
        })
        if (utils.is_define(options.pid)) {
            that.setData({
                pid: options.pid
            })
        }
        wx.getSystemInfo({
            success: (result) => {
                var barHeight = result.screenHeight - result.safeArea.bottom + 20
                that.setData({
                    pdbottom: barHeight + 'px',
                    pdbper: barHeight,
                    picType: options.picType
                })
            },
        })
        that.cropper = that.selectComponent("#image-cropper");
        query.select('#editBottom').boundingClientRect()
        query.exec(function (res) {
            //res就是 所有标签为mjltest的元素的信息 的数组
            //取高度
            that.setData({
                mengHeight: res[0].height,
                pdbper: res[0].height,
            })
        })
        //证件
        if (options.code == '31179418' || options.code == '23002888' || options.code == '29733714' || options.code == '92673031' || options.code == '27007881' || options.code == '43969370' || options.code == '17094958' || options.code == '32663242' || options.code == '85577502' || options.code == '32372752' || options.code == '52895860' || options.code == '33024820' || options.code == '49321510' || options.code == '10765365' || options.code == '12871293') {
            this.setData({
                width: options.w,
                height: options.h,
                code: options.code,
                disable_ratio: true,
                disable_width: false,
                disable_height: false,
                src: options.img
            })
            wx.setNavigationBarTitle({
                title: '证件照编辑',
            })
            // that.cropper.upload();
        }
        //身份证
        if (options.code == 'idCard') {
            console.log(options)
            that.setData({
                width: options.w,
                height: options.h,
                code: options.code,
                disable_ratio: true,
                type: options.type,
                disable_width: false,
                disable_height: false,
                src: options.img
            });
            wx.setNavigationBarTitle({
                title: '身份证编辑',
            })
            // that.cropper.upload();
        }
        //画中画
        if (options.code == '30177105') {
            that.gettmp();
            this.setData({
                width: options.w,
                height: options.h,
                code: options.code,
                disable_ratio: true,
                addList: options.addList,
                disable_width: true,
                disable_height: true,
                src: options.img,
                disable_rotate: false,
                limit_move: false
            })
            wx.setNavigationBarTitle({
                title: '画中画',
            })
        }
        //原片
        if (options.code == '31414754') {
            this.setData({
                width: options.w,
                height: options.h,
                code: options.code,
                disable_ratio: true,
                addList: options.addList,
                disable_width: false,
                disable_height: false,
                src: options.img,
            })
            wx.setNavigationBarTitle({
                title: '相片编辑',
            })
        }
        //卡通形象
        if (options.code == '11543462') {
            this.setData({
                width: options.w,
                height: options.h,
                code: options.code,
                disable_ratio: true,
                addList: options.addList,
                disable_width: false,
                disable_height: false,
                src: options.img,
            })
            wx.setNavigationBarTitle({
                title: '卡通形象',
            })
        }
        //老照片修复
        if (options.code == '12653870') {
            this.setData({
                width: options.w,
                height: options.h,
                code: options.code,
                disable_ratio: true,
                addList: options.addList,
                disable_width: false,
                disable_height: false,
                src: options.img,
            })
            wx.setNavigationBarTitle({
                title: '老照片修复',
            })
        }
        //图片
        if (options.code == '28542179') {
            this.setData({
                width: options.w,
                height: options.h,
                code: options.code,
                disable_ratio: true,
                addList: options.addList,
                disable_width: false,
                disable_height: false,
                src: options.img,
            })
            wx.setNavigationBarTitle({
                title: '图片编辑',
            })
        }
        //滤镜
        if (options.code == '32218178') {
            that.getSpeFilter();
            this.setData({
                width: options.w,
                height: options.h,
                code: options.code,
                disable_ratio: true,
                addList: options.addList,
                disable_width: true,
                disable_height: true,
                src: options.img,
                oldSrc: options.img
            })
            wx.setNavigationBarTitle({
                title: '特效滤镜',
            })
        }

        //胡子特效
        if (options.code == '38668456') {
            that.getbeardS();
            this.setData({
                width: options.w,
                height: options.h,
                code: options.code,
                disable_ratio: true,
                addList: options.addList,
                disable_width: true,
                disable_height: true,
                src: options.img,
                oldSrc: options.img
            })
            wx.setNavigationBarTitle({
                title: '胡子特效',
            })
        }
        //童年穿越
        if (options.code == '26850318') {
            that.getchildhood();
            this.setData({
                width: options.w,
                height: options.h,
                code: options.code,
                disable_ratio: true,
                addList: options.addList,
                disable_width: true,
                disable_height: true,
                src: options.img,
                oldSrc: options.img
            })
            wx.setNavigationBarTitle({
                title: '童年穿越',
            })
        }
        // 毕业照
        if (options.code == '29756116') {
            that.getgraduationS();
            this.setData({
                width: options.w,
                height: options.h,
                code: options.code,
                disable_ratio: true,
                addList: options.addList,
                disable_width: true,
                disable_height: true,
                src: options.img,
                oldSrc: options.img
            })
            wx.setNavigationBarTitle({
                title: '毕业照',
            })
        }
        //跨次元 
        if (options.code == '23844984') {
            that.getdimensional();
            this.setData({
                width: options.w,
                height: options.h,
                code: options.code,
                disable_ratio: true,
                addList: options.addList,
                disable_width: true,
                disable_height: true,
                src: options.img,
                oldSrc: options.img
            })
            wx.setNavigationBarTitle({
                title: '跨次元',
            })
        }
        //人物绘画

        if (options.code == '27814624') {
            that.getdisney();
            this.setData({
                width: options.w,
                height: options.h,
                code: options.code,
                disable_ratio: true,
                addList: options.addList,
                disable_width: true,
                disable_height: true,
                src: options.img,
                oldSrc: options.img
            })
            wx.setNavigationBarTitle({
                title: '人物绘画',
            })
        }
        this.loadimage();
    },
    loadimage(e) {
        // var sc = parseInt(e.detail.width) / parseInt(e.detail.height)
        // // 裁剪框宽高
        // var cw = this.data.width;
        // var ch = this.data.height;
        // if(e.detail.width>e.detail.height){
        //     var nw  = parseInt(ch * sc);
        //     this.setData({
        //         h:ch,
        //         w:nw
        //     })
        //     //高是短边

        // }
        // if(e.detail.width<=e.detail.height){
        //     //宽是短边
        //     var nh = parseInt(cw / sc)
        //     this.setData({
        //         w:cw,
        //         h:nh
        //     })
        // }
        this.cropper.imgReset();
    },
    clickcut(e) {

    },
    end(e) {
        clearInterval(this.data[e.currentTarget.dataset.type]);
    },
})